/*
编写两个函数，分别通过指针传递和引用传递的方式交换两个整型变量的值。在主函数
中测试这两个函数的功能。
*/
#include <iostream>
using namespace std;

void swap1(int *num1, int *num2)
{
    int temp = *num1;
    *num1 = *num2;
    *num2 = temp;
}

void swap2(int &num1, int &num2)
{
    int temp = num1;
    num1 = num2;
    num2 = temp;
}

int main()
{
    int num1 = 99;
    int num2 = 10;
    swap1(&num1, &num2);
    cout << "用指针传递的方式交换两整数的值：" << endl;
    cout << "num1 = " << num1 << "  num2 = " << num2 << endl;

    swap2(num1,num2);
    cout << "用引用传递的方式交换两整数的值：" << endl;
    cout << "num1 = " << num1 << "  num2 = " << num2 << endl;

    return 0;
}
